package ishitong.vehicleManagement.service.biz.impl;

import java.util.List;
import ishitong.common.SysCodeType;
import ishitong.vehicle.common.model.Vehicle;
import ishitong.vehicle.common.service.biz.VehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/** @pdOid bb1c2890-a57e-447e-9985-bd88e6525955 */
@Service(value = "spiVehicleService")
@Transactional
public class SPIVehicleService {
   /** @pdOid 2939bbd8-f7c0-46dd-ac5c-aac2112351d5 */
   @Autowired
   private VehicleService vehicleService;
   /** @pdOid abad6efd-6e46-4d6e-8642-94738ccaa6a4
       @pdRoleInfo migr=yes name=SPISysCodeService assc=association13 */
   @Autowired
   private SPISysCodeService spiSysCodeService;
   
   /** @param vehicle
    * @pdOid 2c9f63c6-70ff-42de-964d-adb6a7051239 */
   private void setVehicleProperty(Vehicle vehicle) {
    vehicle.setPlatetcolor(spiSysCodeService.getSysCodeByCodeAndParentcode(vehicle.getPlatetcolor(), SysCodeType.PLATE_COLOR).getName());
    vehicle.setPlatetype(spiSysCodeService.getSysCodeByCodeAndParentcode(vehicle.getPlatetype(), SysCodeType.PLATE_KIND).getName());
    vehicle.setVehiclecolor(spiSysCodeService.getSysCodeByCodeAndParentcode(vehicle.getVehiclecolor(), SysCodeType.VEHICLE_COLOR).getName());
    vehicle.setVehicletype(spiSysCodeService.getSysCodeByCodeAndParentcode(vehicle.getVehicletype(), SysCodeType.VEHICLE_TYPE).getName());
    vehicle.setUsingcharacter(spiSysCodeService.getSysCodeByCodeAndParentcode(vehicle.getUsingcharacter(), SysCodeType.USE_NATURE).getName());
   //缺车辆分类
   }
   
   /** @param id
    * @pdOid dd3b70a5-55a0-4aef-9f78-08146f574f46 */
   public Vehicle findById(String id) {
   	Vehicle vehicle = new Vehicle();
   	vehicle.setId(Long.valueOf(id));
   	List<Vehicle> lstVehicles = vehicleService.query(vehicle);
   	if (lstVehicles.size() > 0) {
   		setVehicleProperty(lstVehicles.get(0));
   		return lstVehicles.get(0);
   	}
   	return null;
   }
   
   /** @param plateNum
    * @pdOid 068d943b-d015-4c5a-88fe-efb0460f806c */
   public Vehicle findByPlate(String plateNum) {
   	Vehicle vehicle = new Vehicle();
   	vehicle.setPlatenum(plateNum);
   	List<Vehicle> lstVehicles = vehicleService.query(vehicle);
   	if (lstVehicles.size() > 0) {
   		vehicle = lstVehicles.get(0);
   		setVehicleProperty(vehicle);
   		return vehicle;
   	}
   	return null;
   }
   
   /** @param vehicle
    * @pdOid cf0f818c-d196-4e5c-9b93-07568d6e0a09 */
   public List<Vehicle> findByQuery(Vehicle vehicle) {
   	List<Vehicle> lst = vehicleService.query(vehicle);
   	for (Vehicle vh : lst) {
   		setVehicleProperty(vh);
   	}
   	return lst;
   }

}